<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>完善企业资料</title>

	<link href="__PUBLIC__/css/default/index.css" rel="stylesheet" />
	<link href="__PUBLIC__/css/default/global.css" rel="stylesheet" />
	<link href="__PUBLIC__/css/default/data.css" rel="stylesheet" />





	<link rel="stylesheet" href="__CSS__/bootstrap.min.css">
	<link rel="stylesheet" href="__CSS__/font-awesome.min.css">
	<link rel="stylesheet" href="__CSS__/main.css">
	<link rel="stylesheet" href="__CSS__/animate.css">
	<link rel="stylesheet" href="__CSS__/responsive.css">


	<script src="__JS__/jquery.min.js"></script>


	<script type="text/javascript" src="__JS__/distpicker.data.js"></script>
	<script type="text/javascript" src="__JS__/distpicker.js"></script>
	<script type="text/javascript" src="__JS__/ajaxfileupload.js"></script>

</head>

<body style="background-color: #f2f6fa;">
<header>
	<div class="container">
		<div class="row">
			<div class="col-md-3 col-xs-6 col-sm-3">
				<a href="/?/explore/index/" class="logo">
					<img src="__IMG__/logo.png" alt="">
				</a>
			</div>


		</div>
	</div>
</header>

<br/>
<br/>
<br/>

<div class="content">
	<div class="fill_data">
		<div class="fill_title">
			完善企业资料
		</div>
		<div class="fill_ct">
			<div class="select_ct fill_main" style="display: none;">
				<span class="left_nm">所在行业：</span>
				<div class="select_city">

					<select name="pro" id="job">

						<option value="1">IT业</option>

					</select>



				</div>
			</div>
			<div class="select_ct fill_main">
				<span class="left_nm">所在城市：</span>
				<div class="select_city" id="select_city">
					<select name="pro" id="selectpro">
					</select>
					<select name="city" id="selectcity">
					</select>

				</div>
			</div>
			<div class="upload_idimg fill_main">
				<span class="left_nm">营业执照证件照片：</span>
				<div class="upload_ct">
					<div class="upload_tt">
						正面<span>（格式:3M以下的jpg，png或bmp）</span>
					</div>
					<div class="file_up">
						<span class="left_up"><img id="right_img" src="__IMG__/addid.png" alt=""><input type="file" enctype="multipart/form-data" name="image" id="up_right"  onchange="uploadeImage(this,'0');return false;"></span>
						<span class="right_idimg"><img src="__IMG__/company_img.png" alt=""></span>
					</div>
				</div>
			</div>

		</div>
		<div class="complete_btn">
			<span>完成</span>
		</div>
	</div>
</div>

</body>
</html>
<script type="application/javascript">

	var right_img = "";
	$(function () {


		$('#select_city').distpicker({
			autoSelect: false
		});

		$('.complete_btn').click(function () {

			var selectpro  = $('#selectpro').val();
			var selectcity  = $('#selectcity').val();

			if(selectpro== ''){
				alert('请选择省份');
				return false;
			}
			if(selectcity== ''){
				alert('请选择城市');
				return false;
			}
			if(right_img== ''){
				alert('请选择上传证件');
				return false;
			}

			$.post('/update_org',{"province":selectpro,"city":selectcity,"url":right_img},function (result) {

				if(result.code == 200){

					window.location.href="/org_admin";
				}else{
					alert('操作失败');
				}
			},'json');

		});


	});


	function uploadeImage(ele,i) {

		var selected_file =  ele.files[0];

		var formdata = new FormData();
		// 将文件追加到 formdata对象中。
		formdata.append("image",selected_file);
		$.ajax({
			type: "POST",
			url: "upload_cert",
			data:formdata,
			/**
			 * 必须false才会避开jQuery对 formdata 的默认处理
			 * XMLHttpRequest会对 formdata 进行正确的处理
			 */
			processData: false,
			// 告诉jQuery不要去设置Content-Type请求头
			contentType: false,
			dataType: "json",
			success: function(data){
				console.log(data);
				right_img = data.filename;
				$("#right_img").attr("src", getObjectURL(selected_file));

			},
			error: function(jqXHR){
				alert("发生错误：" + jqXHR.status);
			},


		});

	}




	function do_upload(url, file, callback)
	{
		var xhr = new XMLHttpRequest();
		xhr.open('POST', url, true);
		xhr.onload = function(e) {
		};

		xhr.onreadystatechange = function() {

			if (xhr.readyState == 4 && xhr.status == 200) {
				try {
					responseData = $.parseJSON(xhr.responseText);
					if (responseData.errno == 1) {
						callback(responseData.rsm);
					} else {
						alert(responseData.err);
					}
				} catch(err) {
					response = {};
				}
			}
		};
		xhr.send(file);
	}


	function ajaxUpload(ele) {


		var selected_file =  ele.files[0];

		jQuery.ajaxFileUpload({
			url : '/account/ajax/avatar_upload/', //用于文件上传的服务器端请求地址
			secureuri : false, //是否需要安全协议，一般设置为false
			fileElementId :"file_form", //文件上传域的ID
			dataType : 'json', //返回值类型 一般设置为json
			success : function(data, status)//服务器成功响应处理函数
			{
				if(data.success ==true){

					//$("#img_upload").attr("src", data.thumb);
					$("#img_upload").attr("src", getObjectURL(selected_file));

				}else{

					alert(data.error);
				}

			}

		});

		return false;
	};

	function getObjectURL(file) {
		var url = null;
		if (window.createObjectURL != undefined) { // basic
			url = window.createObjectURL(file);
		} else if (window.URL != undefined) { // mozilla(firefox)
			url = window.URL.createObjectURL(file);
		} else if (window.webkitURL != undefined) { // webkit or chrome
			url = window.webkitURL.createObjectURL(file);
		}
		return url;
	}

</script>